/******************************************************************************
 * * modem_adp.c - implementation of modem adaptor
 *
 * *(C) Copyright 2019 Asr International Ltd.
 * * All Rights Reserved
 * ******************************************************************************/
#include "lv_conf.h"

#if USE_LV_WATCH_MODEM_ADAPTOR != 0

/*********************
*      INCLUDES
*********************/
#include <stdio.h>
#include "lv_conf.h"
#include "lvgl.h"
#include "ui_global.h"
#include "ui_inter_msg_interface.h"
#include "mmi_modem_adaptor_main.h"
#include "mmi_modemadp_interface.h"
#include "../framework/message/phone_msg_handle.h"
/*********************
 *      DEFINES
 *********************/

/**********************
 *      TYPEDEFS
 **********************/

/**********************
 *  STATIC PROTOTYPES
 **********************/

/**********************
 *  STATIC VARIABLES
 **********************/

extern TASK_HANDLE *gui_task_id;
extern TASK_HANDLE *modem_adp_task_id;

MODEM_WAKE_UP_REASON modem_wake_up_reason = MODEM_WAKE_UP_OTHERS;

/**
 *
 * This message is sent to the calling mobile station
 *  to response that the get the current calls command
 * param simId:  MMI_MODEM_SIM_ID
 * param index:  Connection index
 * return  void
 */
void MMI_Modem_Call_Rsp_Get_Current_Calls(MMI_Modem_Call_Rsp_Get_Current_Calls_t * calls)
{
    if(0 == Hal_Pm_Get_State()) Hal_Pm_WakeUp();

    mmi_msg_call_response_get_cur_calls_t * msg;

    msg = (mmi_msg_call_response_get_cur_calls_t *)lv_mem_alloc(sizeof(mmi_msg_call_response_get_cur_calls_t));

    msg->header.MsgId = MMI_MODEM_CALL_RESPONSE_GET_CUR_CALLS;
    msg->calls = calls;

    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
}

/**
 * Indicates ATD OK or cme error for an outgoing call.
 * param simId:  MMI_MODEM_SIM_ID
 * param isNoCarrier:  uint8_t,0 is OK,1 is cme error
 * return  void
 */
void MMI_Modem_Call_Response_Dial(MMI_MODEM_SIM_ID simId, uint8_t isOk)
{
    if(0 == Hal_Pm_Get_State()) Hal_Pm_WakeUp();

    mmi_msg_call_response_dial_t * msg;

    msg = (mmi_msg_call_response_dial_t *)lv_mem_alloc(sizeof(mmi_msg_call_response_dial_t));

    msg->header.MsgId = MMI_MODEM_CALL_RESPONSE_DIAL;
    msg->simid = simId;
    msg->isOk = isOk;

    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
}

/**
 * Indicates the Mute control after every +CMUT?. (+CMUT:)
 * +CMUT: <n>
 * +CME ERROR: <err>
 *
 * param simId: MMI_MODEM_SIM_ID
 * param cmut:  MMI_MODEM_CALL_RESPONSE_CMUT *
 * return  void
 */
void MMI_Modem_Call_Response_Cmut(MMI_MODEM_SIM_ID simId, MMI_Modem_Call_Response_Cmut_t * cmut)
{
    if(0 == Hal_Pm_Get_State()) {
        lv_mem_free(cmut);
        return;
    }

    mmi_msg_call_response_cmut_t * msg = NULL;

    msg = (mmi_msg_call_response_cmut_t *)lv_mem_alloc(sizeof(mmi_msg_call_response_cmut_t));

    msg->header.MsgId = MMI_MODEM_CALL_RESPONSE_CMUT;
    msg->simid = simId;
    msg->cmut  = cmut;

    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
}

/**
 * report the lte cells information in engineer mode
 * param (in) MMI_Modem_Lte_Cells_t  *ltecells
 * return  void
 */
void MMI_Modem_Lte_Cells_Ind(MMI_Modem_Lte_Cells_t * ltecells)
{
    if(0  == Hal_Pm_Get_State()){
        lv_mem_free(ltecells);
        return;
    }

    mmi_msg_lte_cells_info_t * msg;

    msg = (mmi_msg_lte_cells_info_t *)lv_mem_alloc(sizeof(mmi_msg_lte_cells_info_t));

    msg->header.MsgId = MMI_MODEM_LTE_CELLS_INFO;
    msg->pltecells = ltecells;

    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
}

/**
 * report the gsm cells information in engineer mode
 * param (in) MMI_Modem_Lte_Cells_t  *ltecells
 * return  void
 */
void MMI_Modem_Gsm_Cells_Ind(MMI_Modem_Gsm_Cells_t * gsmcells)
{
    if(0  == Hal_Pm_Get_State()) {
        lv_mem_free(gsmcells);
        return;
    }

    mmi_msg_gsm_cells_info_t * msg;

    msg = (mmi_msg_gsm_cells_info_t *)lv_mem_alloc(sizeof(mmi_msg_gsm_cells_info_t));

    msg->header.MsgId = MMI_MODEM_GSM_CELLS_INFO;
    msg->pgsmcells = gsmcells;

    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
}

/**
 * query current call active status
 * param (in) void
 * return  bool
 */
bool watch_modem_call_get_call_active_status(void)
{
    return(MMI_ModemAdp_Call_Get_Call_Active_Status());
}

/**
 * Get wakeup reason from modem
 * param (in) void
 * return  MODEM_WAKE_UP_REASON
 */
MODEM_WAKE_UP_REASON MMI_Modem_Adp_Get_Wakeup_Reason_Req(void)
{
    uint8_t reason = modem_wake_up_reason;

    modem_wake_up_reason = MODEM_WAKE_UP_OTHERS;
    return reason;
}

/**
 * power up SIMx confrom
 * param (in) simId: MMI_MODEM_SIM_ID
 * return  void
 */
void MMI_Modem_Power_Up_Cnf(MMI_MODEM_SIM_ID simId)
{
    if(0  == Hal_Pm_Get_State()) return;

    mmi_msg_power_up_cnf_t * msg;

    msg = (mmi_msg_power_up_cnf_t *)lv_mem_alloc(sizeof(mmi_msg_power_up_cnf_t));

    msg->header.MsgId = MMI_MODEM_POWER_UP_CNF;
    msg->simid = simId;

    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
}

/**
 * power off SIMx confrom
 * param (in) simId: MMI_MODEM_SIM_ID
 * return  void
 */
void MMI_Modem_Power_Off_Cnf(MMI_MODEM_SIM_ID simId)
{
    if(0 == Hal_Pm_Get_State()) return;

    mmi_msg_power_off_cnf_t * msg;

    msg = (mmi_msg_power_off_cnf_t *)lv_mem_alloc(sizeof(mmi_msg_power_off_cnf_t));

    msg->header.MsgId = MMI_MODEM_POWER_OFF_CNF;
    msg->simid = simId;

    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
}

/**
 * Operator(short name) indicator reported when register at the first time
 * param (in) SimId: MMI_MODEM_SIM_ID
 * param (in) Operator: char*
 * return  void
 */
void MMI_Modem_Operator_Ind(MMI_MODEM_SIM_ID SimId, char * Operator, MMI_MODEM_PLMN_RAT Rat)
{
    if(0 == Hal_Pm_Get_State()) {
        lv_mem_free(Operator);
        return;
    }

    mmi_msg_operator_ind_t * msg;

    msg = (mmi_msg_operator_ind_t *)lv_mem_alloc(sizeof(mmi_msg_operator_ind_t));

    msg->header.MsgId = MMI_MODEM_OPERATOR_IND;
    msg->simid = SimId;
    msg->operator = Operator;
    msg->rat = Rat;

    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
}

/**
 * SIM status indicator
 * param (in) SimId: MMI_MODEM_SIM_ID
 * param (in) SimPresent: uint8_t
 * return  void
 */
void MMI_Modem_Sim_Status_Ind(MMI_Modem_Sim_Status_t * SimStatus)
{
    if(0 == Hal_Pm_Get_State()) {
        lv_mem_free(SimStatus);
        return;
    }

    mmi_msg_sim_status_ind_t * msg;

    msg = (mmi_msg_sim_status_ind_t *)lv_mem_alloc(sizeof(mmi_msg_sim_status_ind_t));

    msg->header.MsgId = MMI_MODEM_SIM_STATUS_IND;
    msg->SimStatus = SimStatus;

    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
}

/**
 *
 * This message is sent to the calling mobile station
 *  to indicate that the call is originating. (after ATD <number>;)
 * param simId:  MMI_MODEM_SIM_ID
 * param index:  Connection index
 * return  void
 */
void MMI_Modem_Call_Response_Originating(MMI_MODEM_SIM_ID simId, int32_t index)
{
    if(0 == Hal_Pm_Get_State()) Hal_Pm_WakeUp();

    mmi_msg_call_response_originating_t * msg;

    msg = (mmi_msg_call_response_originating_t *)lv_mem_alloc(sizeof(mmi_msg_call_response_originating_t));

    msg->header.MsgId = MMI_MODEM_CALL_RESPONSE_ORIGINATING;
    msg->simid = simId;
    msg->index = index;

    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
}

/**
 *
 * This message is sent to the calling mobile station
 *  to indicate that the called user alerting has been initiated.
 * param simId:  MMI_MODEM_SIM_ID
 * param index:  Connection index
 * return  void
 */
void MMI_Modem_Call_Response_Alerting(MMI_MODEM_SIM_ID simId, int32_t index)
{
    if(0 == Hal_Pm_Get_State()) Hal_Pm_WakeUp();

    mmi_msg_call_response_alerting_t * msg;

    msg = (mmi_msg_call_response_alerting_t *)lv_mem_alloc(sizeof(mmi_msg_call_response_alerting_t));

    msg->header.MsgId = MMI_MODEM_CALL_RESPONSE_ALERTING;
    msg->simid = simId;
    msg->index = index;

    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
}

/**
 *
 * This message is sent to the called mobile station
 *  to indicate an incoming call (voice, data or fax). (RING)
 * param simId:  MMI_MODEM_SIM_ID
 * param index:  Connection index
 * return  void
 */
void MMI_Modem_Call_Response_Ring(MMI_MODEM_SIM_ID simId, int32_t index)
{
    if(0 == Hal_Pm_Get_State()) {
        modem_wake_up_reason = MODEM_WAKE_UP_RING;
        Hal_Pm_WakeUp();
    }

    mmi_msg_call_response_ring_t * msg;

    msg = (mmi_msg_call_response_ring_t *)lv_mem_alloc(sizeof(mmi_msg_call_response_ring_t));

    msg->header.MsgId = MMI_MODEM_CALL_RESPONSE_RING;
    msg->simid = simId;
    msg->index = index;

    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
}

/**
 * This message is sent to the calling/called mobile station
 *  to indication that the call is connected.
 * param simId:  MMI_MODEM_SIM_ID
 * param index:  Connection index
 * return  void
 */
void MMI_Modem_Call_Response_Connect(MMI_MODEM_SIM_ID simId, int32_t index)
{
    if(0 == Hal_Pm_Get_State()) return;

    mmi_msg_call_response_connect_t * msg;

    msg = (mmi_msg_call_response_connect_t *)lv_mem_alloc(sizeof(mmi_msg_call_response_connect_t));

    msg->header.MsgId = MMI_MODEM_CALL_RESPONSE_CONNECT;
    msg->simid = simId;
    msg->index = index;

    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
}

/**
 * This message is sent to the calling/called mobile station
 *  to indication that the call is disconnected.
 * param simId:  MMI_MODEM_SIM_ID
 * param index:  Connection index
 * return  void
 */
void MMI_Modem_Call_Response_Disconnect(MMI_MODEM_SIM_ID simId, int32_t index)
{
    if(0 == Hal_Pm_Get_State()) Hal_Pm_WakeUp();

    mmi_msg_call_response_disconnect_t * msg;

    msg = (mmi_msg_call_response_disconnect_t *)lv_mem_alloc(sizeof(mmi_msg_call_response_disconnect_t));

    msg->header.MsgId = MMI_MODEM_CALL_RESPONSE_DISCONNECT;
    msg->simid = simId;
    msg->index = index;

    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
}

/**
 * Indicates a disconnect for Call Clearing or a Call Failed for an outgoing call. (NO CARRIER)
 * param simId:  MMI_MODEM_SIM_ID
 * param index:  Connection index
 * param isNoCarrier:  uint8_t
 * return  void
 */
void MMI_Modem_Call_Response_No_Carrier(MMI_MODEM_SIM_ID simId, int32_t index, uint8_t isNoCarrier)
{
    if(0 == Hal_Pm_Get_State()) Hal_Pm_WakeUp();

    mmi_msg_call_response_no_carrier_t * msg;

    msg = (mmi_msg_call_response_no_carrier_t *)lv_mem_alloc(sizeof(mmi_msg_call_response_no_carrier_t));

    msg->header.MsgId = MMI_MODEM_CALL_RESPONSE_NO_CARRIER;
    msg->simid = simId;
    msg->index = index;
    msg->isNoCarrier = isNoCarrier;

    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
}

/**
 * Indicates the calling line identity of the calling party after every RING/+CRING. (+CLIP:)
 * +CLIP: <number>,<type>
 *
 * param simId:  MMI_MODEM_SIM_ID
 * param index:  Connection index
 * param clip:  MMI_MODEM_CALL_RESPONSE_CLIP *
 * return  void
 */
void MMI_Modem_Call_Response_Clip(MMI_MODEM_SIM_ID simId, int32_t index,
                                  MMI_Modem_Call_Response_Clip_t * clip)
{
    mmi_msg_call_response_clip_t * msg;

    msg = (mmi_msg_call_response_clip_t *)lv_mem_alloc(sizeof(mmi_msg_call_response_clip_t));

    msg->header.MsgId = MMI_MODEM_CALL_RESPONSE_CLIP;
    msg->simid = simId;
    msg->index = index;
    msg->clip  = clip;

    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
}

/**
 * Indicates Call Waiting (CW) information (when enabled) for an incoming call. (+CCWA:)
 * +CCWA: <number>,<type>,<class>,[<alpha>][,<CLI validity>[,<subaddr>,<satype>[,<priority>]]]
 *
 * param simId:  MMI_MODEM_SIM_ID
 * param index:  Connection index
 * param ccwa:  MMI_MODEM_CALL_RESPONSE_CCWA *
 * return  void
 */
void MMI_Modem_Call_Response_Ccwa(MMI_MODEM_SIM_ID simId, int32_t index,
                                  MMI_Modem_Call_Response_Ccwa_t * ccwa)
{
    // todo
}

/**
 * Indicats the call state is changed
 *
 * param state:  MMI_MODEM_CALL_RESPONSE_STATE_CHANGE *
 * return  void
 */
void MMI_Modem_Call_Response_State_Change(MMI_Modem_Call_Response_State_Change_t * state)
{
    uint8_t i;

    if(0 == Hal_Pm_Get_State()) {
        for(i = 0; i < state->count; i++) {
            lv_mem_free(state->calls[i].number);
            lv_mem_free(state->calls[i].name);
        }
        lv_mem_free(state->calls);
        lv_mem_free(state);
        return;
    }

    mmi_msg_call_response_state_change_t * msg;

    msg = (mmi_msg_call_response_state_change_t *)lv_mem_alloc(sizeof(mmi_msg_call_response_state_change_t));

    msg->header.MsgId = MMI_MODEM_CALL_RESPONSE_STATE_CHANGE;
    msg->state = state;

    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
}

/**
 * Indicates whether remote state is hold
 *
 * param simId:  MMI_MODEM_SIM_ID
 * param index:  Connection index
 * param IsHold: uint8_t ture for hold, and false for unhold
 * return  void
 */
void MMI_Modem_Call_Response_Remote_Hold(MMI_MODEM_SIM_ID SimId, int32_t Index, uint8_t IsHold)
{
    // todo
}

/**
 * indicate that PIN status changed
 * param (in) simId      :  MMI_MODEM_SIM_ID
 *       (in) PinReqType :  MMI_MODEM_PIN_STATUS_TYPE
 * return  void
 */
void  MMI_Modem_Pin_Status_Change_Ind(MMI_MODEM_SIM_ID SimId,
                                      MMI_MODEM_PIN_STATUS_TYPE PinReqType)
{
    if(0 == Hal_Pm_Get_State()) return;

    mmi_msg_pin_status_change_ind_t * msg;

    msg = (mmi_msg_pin_status_change_ind_t *)lv_mem_alloc(sizeof(mmi_msg_pin_status_change_ind_t));

    msg->header.MsgId = MMI_MODEM_PIN_STATUS_CHANGE_IND;
    msg->simid = SimId;
    msg->pinreqtype = PinReqType;

    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
}
/**
 * plmn search confirm
 * param (in) PlmnSearchCnf:  MMI_Modem_Plmn_Search_Cnf_t
 * return void:
 */
void MMI_Modem_Plmn_Search_Cnf(MMI_Modem_Plmn_Search_Cnf_t * PlmnSearchCnf)
{
    mmi_msg_plmn_search_cnf_t * msg;

    msg = (mmi_msg_plmn_search_cnf_t *)lv_mem_alloc(sizeof(mmi_msg_plmn_search_cnf_t));

    msg->header.MsgId = MMI_MODEM_PLMN_SEARCH_CNF;
    msg->plmnsearchcnf = PlmnSearchCnf;

    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
}

/**
 * configure SS service call wait confirm
 * param (in) SimId  : MMI_MODEM_SIM_ID
 *       (in) Result : MMI_MODEM_RESULT
 * return void:
 */
void MMI_Modem_Call_Forward_Set_Cnf(MMI_MODEM_SIM_ID SimId, MMI_MODEM_RESULT Result)
{
    // todo
}

/**
 * query SS service call wait confirm
 * param (in) SimId  : MMI_MODEM_SIM_ID
 * param (in) Result : MMI_MODEM_RESULT
 * param (in) CallForwardInfo : MMI_Modem_Call_Forward_Info_t(response of check status)
 * return void
 */
void MMI_Modem_Call_Forward_Query_Cnf(MMI_MODEM_SIM_ID SimId, MMI_MODEM_RESULT Result,
                                      MMI_Modem_Call_Forward_Info_t * CallForwardInfo)
{
    // todo
}

/**
 * configure SS service call wait confirm
 * param (in) SimId : MMI_MODEM_SIM_ID
 * param (in) CallWaitOn : uint8_t (true means call wait on)
 * return void:
 */
void MMI_Modem_Call_Wait_Set_Cnf(MMI_MODEM_SIM_ID SimId, MMI_MODEM_RESULT Result)
{
    // todo
}

/**
 * query SS service call wait confirm
 * param (in) SimId : MMI_MODEM_SIM_ID
 * param (in) CallWaitOn : uint8_t
 * return void
 */
void MMI_Modem_Call_Wait_Query_Cnf(MMI_MODEM_SIM_ID SimId, uint8_t CallWaitOn, MMI_MODEM_RESULT Result)
{
    // todo
}

/**
 * Signal bar indication
 * param (in) Bar:  MMI_MODEM_SIGNAL_BAR
 * return  void
 */
void MMI_Modem_Signal_Bar_Ind(MMI_MODEM_SIM_ID SimId, MMI_MODEM_SIGNAL_BAR Bar)
{
    if(0 == Hal_Pm_Get_State()) return;

    mmi_msg_signal_bar_ind_t * msg;

    msg = (mmi_msg_signal_bar_ind_t *)lv_mem_alloc(sizeof(mmi_msg_signal_bar_ind_t));

    msg->header.MsgId = MMI_MODEM_SIGNAL_BAR_IND;
    msg->simid = SimId;
    msg->bar = Bar;

    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
}

/**
 * time auto-update indication
 * param (in) :
 * return  void
 */
void MMI_Modem_Time_Update_Ind(MMI_Modem_Time_Info_t * TimeInfo)
{
    if(0 == Hal_Pm_Get_State()) {
        lv_mem_free(TimeInfo);
        return;
    }

    mmi_msg_time_update_ind_t * msg;

    msg = (mmi_msg_time_update_ind_t *)lv_mem_alloc(sizeof(mmi_msg_time_update_ind_t));

    msg->header.MsgId = MMI_MODEM_TIME_UPDATE_IND;
    msg->TimeInfo = TimeInfo;

    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
}

/**
 * Response for getting phone book status
 * param (in) SimId: MMI_MODEM_SIM_ID
 * param (in) PhkStatus: MMI_Modem_Phonebook_Status*
 * return  void
 */
void MMI_Modem_Get_Phonebook_Status_Cnf(MMI_MODEM_SIM_ID SimId,
                                        MMI_Modem_Phonebook_Status * PhkStatus)
{
    mmi_msg_get_phonebook_status_cnf_t * msg;

    msg = (mmi_msg_get_phonebook_status_cnf_t *)lv_mem_alloc(sizeof(mmi_msg_get_phonebook_status_cnf_t));

    msg->header.MsgId = MMI_MODEM_GET_PHONEBOOK_STATUS_CNF;
    msg->simid = SimId;
    msg->PhkStatus = PhkStatus;

    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
}

/**
 * Response for updating contact into phone book
 * param (in) SimId: MMI_MODEM_SIM_ID
 * param (in) WrittenIndex: uint16_t
 * return  void
 */
void MMI_Modem_Write_Phonebook_Cnf(MMI_MODEM_SIM_ID SimId, uint16_t WrittenIndex)
{
    mmi_msg_write_phonebook_cnf_t * msg;

    msg = (mmi_msg_write_phonebook_cnf_t *)lv_mem_alloc(sizeof(mmi_msg_write_phonebook_cnf_t));

    msg->header.MsgId = MMI_MODEM_WRITE_PHONEBOOK_CNF;
    msg->simid = SimId;
    msg->writtenindex = WrittenIndex;

    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
}

/**
 * Response for reading contacts from phone book
 * param (in) SimId: MMI_MODEM_SIM_ID
 * param (in) Contact: MMI_Modem_Contact*
 * param (in) Number: uint16_t
 * param (in) End: BOOL
 * return  void
 */
void MMI_Modem_Read_Phonebook_Cnf(MMI_MODEM_SIM_ID SimId,
                                  MMI_Modem_Contact * Contact,
                                  uint16_t Number,
                                  BOOL End)
{
    mmi_msg_read_phonebook_cnf_t * msg;

    msg = (mmi_msg_read_phonebook_cnf_t *)lv_mem_alloc(sizeof(mmi_msg_read_phonebook_cnf_t));

    msg->header.MsgId = MMI_MODEM_READ_PHONEBOOK_CNF;
    msg->simid = SimId;
    msg->contact = Contact;
    msg->number = Number;
    msg->end = End;

    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
}

/**
 * Indicate When phone book has been loaded by CP
 * param (in) SimId: MMI_MODEM_SIM_ID
 * return  void
 */
void MMI_Modem_Phonebook_Init_Ind(MMI_MODEM_SIM_ID SimId)
{
    mmi_msg_phonebook_init_ind_t * msg;

    msg = (mmi_msg_phonebook_init_ind_t *)lv_mem_alloc(sizeof(mmi_msg_phonebook_init_ind_t));

    msg->header.MsgId = MMI_MODEM_PHONEBOOK_INIT_IND;
    msg->simid = SimId;

    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
}

/**
 * send new sms cnf
 * param (in) pSendSmsCnf: MMI_Modem_Send_Sms_Cnf_t
 * return  void
 */
void MMI_Modem_Send_Sms_Cnf(MMI_Modem_Send_Sms_Cnf_t * pSendSmsCnf)
{
    if(0 == Hal_Pm_Get_State()) {
        lv_mem_free(pSendSmsCnf);
        return;
    }

    mmi_msg_send_sms_cnf_t * msg;

    msg = (mmi_msg_send_sms_cnf_t *)lv_mem_alloc(sizeof(mmi_msg_send_sms_cnf_t));

    msg->header.MsgId = MMI_MODEM_SEND_SMS_CNF;
    msg->psendsmscnf = pSendSmsCnf;

    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
}

/**
 * delete sms cnf
 * param (in) Result:MMI_MODEM_SMS_RESULT_TYPE
 * return  void
 */
void MMI_Modem_Delete_Sms_Cnf(MMI_MODEM_SMS_RESULT_TYPE Result)
{
    // todo
}

/**
 * read sms info cnf
 * param (in) pReadSmsInfoCnf: MMI_Modem_Read_Sms_Info_Cnf_t
 * return  void
 */
void MMI_Modem_Read_Sms_Info_Cnf(MMI_Modem_Read_Sms_Info_Cnf_t * pReadSmsInfoCnf)
{
    if(0 == Hal_Pm_Get_State()) return;

    mmi_msg_read_sms_info_cnf_t * msg;

    msg = (mmi_msg_read_sms_info_cnf_t *)lv_mem_alloc(sizeof(mmi_msg_read_sms_info_cnf_t));

    msg->header.MsgId = MMI_MODEM_READ_SMS_INFO_CNF;
    msg->preadsmsinfocnf = pReadSmsInfoCnf;

    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
}

/**
 * read sms detail on sim cnf
 * param (in) pReadSmsCnf: MMI_Modem_Read_Sms_Detail_On_Sim_Cnf_t
 * return  void
 */
void MMI_Modem_Read_Sms_Detail_On_Sim_Cnf(
    MMI_Modem_Read_Sms_Detail_On_Sim_Cnf_t * pReadSmsCnf)
{
    if(0 == Hal_Pm_Get_State()) Hal_Pm_WakeUp();

    mmi_msg_read_sms_detail_on_sim_cnf_t * msg;

    msg = (mmi_msg_read_sms_detail_on_sim_cnf_t *)lv_mem_alloc(sizeof(mmi_msg_read_sms_detail_on_sim_cnf_t));

    msg->header.MsgId = MMI_MODEM_READ_SMS_DETAIL_ON_SIM_CNF;
    msg->preadsmscnf = pReadSmsCnf;

    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
}

/**
 * get sms centre number cnf
 * param (in) pGetSmscCnf: MMI_Modem_Get_Smsc_Cnf_t
 * return  void
 */
void MMI_Modem_Get_Smsc_Cnf(MMI_Modem_Get_Smsc_Cnf_t * pGetSmscCnf)
{
    if(0 == Hal_Pm_Get_State()) {
        lv_mem_free(pGetSmscCnf);
        return;
    }

    mmi_msg_get_smsc_cnf_t * msg;

    msg = (mmi_msg_get_smsc_cnf_t *)lv_mem_alloc(sizeof(mmi_msg_get_smsc_cnf_t));

    msg->header.MsgId = MMI_MODEM_GET_SMSC_CNF;
    msg->pgetsmsccnf = pGetSmscCnf;

    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
}

/**
 * set sms centre number cnf
 * param (in) Result:MMI_MODEM_SMS_RESULT_TYPE
 * return  void
 */
void MMI_Modem_Set_Smsc_Cnf(MMI_MODEM_SMS_RESULT_TYPE Result)
{
    // todo
}

/**
 * set delivery report flg cnf
 * param (in) Result:MMI_MODEM_SMS_RESULT_TYPE
 * return  void
 */
void MMI_Modem_Set_Delivery_Rep_Cnf(MMI_MODEM_SMS_RESULT_TYPE Result)
{
    // todo
}

/**
 * report new sms ind
 * param (in) pRepNewSms:MMI_Modem_Report_New_Sms_Ind_t
 * return  void
 */
void MMI_Modem_Rep_New_Sms_Ind(MMI_Modem_Report_New_Sms_Ind_t * pRepNewSms)
{
    if(0 == Hal_Pm_Get_State()) Hal_Pm_WakeUp();

    mmi_msg_rep_new_sms_ind_t * msg;

    msg = (mmi_msg_rep_new_sms_ind_t *)lv_mem_alloc(sizeof(mmi_msg_rep_new_sms_ind_t));

    msg->header.MsgId = MMI_MODEM_REP_NEW_SMS_IND;
    msg->prepnewsms = pRepNewSms;

    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
}

/**
 * report new status report ind
 * param (in) pRepNewStsRep:MMI_Modem_Response_Sms_Status_Rep_Ind_t
 * return  void
 */
void MMI_Modem_Sms_Status_Rep_Ind(MMI_Modem_Response_Sms_Status_Rep_Ind_t * pSmsStsRep)
{
    // todo
}

/**
 * report SMS storage status of SIM
 * param (in) pRepSimSmsStaInd: MMI_Modem_SIM_SMS_Storage_Status_Ind
 * return  void
 */
void MMI_Modem_SIM_SMS_Storage_Status_Ind(
    MMI_Modem_SIM_SMS_Storage_Status_Ind_t * pRepSimSmsStaInd)
{
    // todo
}

/**
 * send Ussd cnf
 * param (in) pSendUssdCnf: MMI_Modem_Send_Ussd_Cnf_t
 * return  void
 */
void MMI_Modem_Send_Ussd_Cnf(MMI_Modem_Send_Ussd_Cnf_t * pSendUssdCnf)
{
    // todo
}

/**
 * report the nw ims vops status
 * param (in) MMI_MODEM_SIM_ID simId
 * return  void
 */
void MMI_Modem_Ims_Vops_Ind(MMI_MODEM_SIM_ID simId)
{
    // todo
}

/**
 * report the calibration result in engineer mode
 * param (in) ucResult: uint8_t
 * return  void
 */
void MMI_Modem_Cali_Rslt_Ind(UINT8 ucResult)
{
    // todo
}

/**
 * report the SN information in engineer mode
 * param (in) pSn: INT8*
 *            ucResult: UINT8
 * return  void
 */
void MMI_Modem_Sn_Info_Ind(INT8 * pSn)
{
    // todo
}

#endif /*USE_LV_WATCH_MODEM_ADAPTOR*/
